package com.trg.generaltool.util.file;

import org.apache.commons.io.FileUtils;

import java.io.File;
import java.io.IOException;

/**
 * ClassName: FileMove
 * Description:
 * date: 2021-02-05 15:00
 * 文件移动到另外一个文件夹
 * @author tangrg
 * @since JDK 1.8
 */
public class FileMove {
    public static void main(String[] args) {
        try {
            for (int i = 1983; i <= 2017; i++) {
                String fileName = "Z_NAFP_C_BAQH_" + i + "0201000000_P_BCC_AGCM2.2_gh0500_1.0_MN_00.nc";
                String filePath = "T:\\DERF2\\" + i + "\\"+fileName;
                String dest = "Z:\\DERF2\\beifen\\"+ i + "\\"+fileName;
                File file = new File(filePath);
                if (file.exists()) {
                    copyFileByApacheCommonsIO(new File(filePath),new File(dest));
                    System.out.println("移动成功:"+fileName);
                } else { // 不存在的文件
                    System.out.println("读取Derf文件不存在:" + fileName);
                }
            }

//	            String source  = "E:\\Z_NAFP_C_BAQH_20160324000000_P_BCC_AGCM2.2_gh0500_1.0_DS_00.nc";
//	            String dest = "E:\\S2S2\\Z_NAFP_C_BAQH_20160324000000_P_BCC_AGCM2.2_gh0500_1.0_DS_00.nc";

        }catch (Exception e ){
            e.printStackTrace();
        }

    }
    private static void  copyFileByApacheCommonsIO(File source, File dest) throws IOException {

        FileUtils.copyFile(source,dest);
    }
}
